package com.wlz.basic.server;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOutboundHandlerAdapter;
import io.netty.channel.ChannelPromise;
import io.netty.util.CharsetUtil;

public class NettyServerOutBoundHandler extends ChannelOutboundHandlerAdapter {

    @Override
    public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
        System.out.println("out one write");
        ByteBuf outBuffer = Unpooled.copiedBuffer("hi man", CharsetUtil.UTF_8);
        ctx.writeAndFlush(outBuffer);
    }

    @Override
    public void read(ChannelHandlerContext ctx) throws Exception {

        super.read(ctx);
//        ctx.channel().writeAndFlush(buffer);
        /*
        通常的outbindhandler实现read方法用于拦截协议校验或者安全校验等功能，
       通过拦截调用super.read，否则直接给客户端返回数据，
        */
    }
}
